﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// SmoothMagnifyEffect Effect
    /// </summary>
    public class SmoothMagnifyEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(SmoothMagnifyEffect), new UIPropertyMetadata(new Point(0.5, 0.5), ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty InnerRadiusProperty = DependencyProperty.Register("InnerRadius", typeof(double), typeof(SmoothMagnifyEffect), new UIPropertyMetadata(.2, ShaderEffect.PixelShaderConstantCallback(2)));
        public static readonly DependencyProperty MagnificationProperty = DependencyProperty.Register("Magnification", typeof(double), typeof(SmoothMagnifyEffect), new UIPropertyMetadata(2.0, ShaderEffect.PixelShaderConstantCallback(3)));
        public static readonly DependencyProperty OuterRadiusProperty = DependencyProperty.Register("OuterRadius", typeof(double), typeof(SmoothMagnifyEffect), new UIPropertyMetadata(.27, ShaderEffect.PixelShaderConstantCallback(4)));
        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(SmoothMagnifyEffect), 0);

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(SmoothMagnifyEffect.InputProperty));
            }
            set
            {
                this.SetValue(SmoothMagnifyEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Center du Shader
        /// </summary>
        public Point Center
        {
            get
            {
                return ((Point)this.GetValue(SmoothMagnifyEffect.CenterProperty));
            }
            set
            {
                this.SetValue(SmoothMagnifyEffect.CenterProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété InnerRadius du Shader
        /// </summary>
        public double InnerRadius
        {
            get
            {
                return ((double)this.GetValue(SmoothMagnifyEffect.InnerRadiusProperty));
            }
            set
            {
                this.SetValue(SmoothMagnifyEffect.InnerRadiusProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Magnification du Shader
        /// </summary>
        public double Magnification
        {
            get
            {
                return ((double)this.GetValue(SmoothMagnifyEffect.MagnificationProperty));
            }
            set
            {
                this.SetValue(SmoothMagnifyEffect.MagnificationProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété OuterRadius du Shader
        /// </summary>
        public double OuterRadius
        {
            get
            {
                return ((double)this.GetValue(SmoothMagnifyEffect.OuterRadiusProperty));
            }
            set
            {
                this.SetValue(SmoothMagnifyEffect.OuterRadiusProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static SmoothMagnifyEffect()
        {
            SmoothMagnifyEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/SmoothMagnify.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public SmoothMagnifyEffect()
        {
            this.PixelShader = SmoothMagnifyEffect._PixelShader;

            this.UpdateShaderValue(SmoothMagnifyEffect.CenterProperty);
            this.UpdateShaderValue(SmoothMagnifyEffect.InnerRadiusProperty);
            this.UpdateShaderValue(SmoothMagnifyEffect.OuterRadiusProperty);
            this.UpdateShaderValue(SmoothMagnifyEffect.MagnificationProperty);
            this.UpdateShaderValue(SmoothMagnifyEffect.InputProperty);
        }

        #endregion
    }
}
